<template>
  <div style='background-color:rgb(1,50,111);'>
    <BasicTable id='workTaskTableContainer' @register="registerTable">
      <template #tableTitle>
        <img src="/@/assets/twoHome/title-icon.png" alt="">
        <span style="font-size: 24px;color: aliceblue;"> 维保工单 </span>
      </template>
      <!-- <template #toolbar>
        <a-button type="primary" @click="handleForm({})" v-auth="'maintenance:management:maintenanceWorkTask:edit'">
          <Icon icon="i-fluent:add-12-filled" /> {{ t('新增') }}
        </a-button>
      </template> -->
      <template #firstColumn="{ record }">
        <a @click="handleForm({ tid: record.tid })">
          {{ record.enterpriseCode }}
        </a>
      </template>
      <template #abnormalPic="{ record }">
        <Image v-if="record.abnormalPic" :src="record.abnormalPic" width="100" height="100" alt="" />
        <div style="height: 100px;text-align: center;line-height: 100px;color:#32CD32" v-else>
          <img src="/@/assets/images/noData.png" style="width: 150px;height:auto;" alt="">
        </div>
      </template>
      <template #completeUrl="{ record }">
        <Image style="height: 100px" v-if="record.completeUrl" :src="record.completeUrl" width="100" height="100" alt="" />
        <div style="height: 100px;text-align: center;line-height: 100px;color:#32CD32" v-else>
          <img src="/@/assets/images/noData.png" style="width: 150px;height:auto;" alt="">
        </div>
      </template>
    </BasicTable>
  </div>
</template>
<script lang="ts" setup name="MaintenanceWorkTask">
  import { unref, ref } from 'vue';
  import { useI18n } from '/@/hooks/web/useI18n';
  import { useMessage } from '/@/hooks/web/useMessage';
  import { router } from '/@/router';
  import { Icon } from '/@/components/Icon';
  import { BasicTable, BasicColumn, useTable } from '/@/components/Table';
  import { maintenanceWorkTaskDelete, maintenanceWorkTaskListData } from '/@/api/maintenance.management/maintenanceWorkTask';
  import { useDrawer } from '/@/components/Drawer';
  import { useModal } from '/@/components/Modal';
  import { BpmRuntimeTrace } from '/@/components/Bpm';
  import { FormProps } from '/@/components/Form';
  import { officeTreeData } from '/@/api/sys/office';
  import { inDeviceManagementListData } from '/@/api/device.management/inDeviceManagement';
  import { unitEnterpriseDominantListData } from '/@/api/unitmanage/unitEnterpriseDominant';
  import { Image } from 'ant-design-vue';

  const { t } = useI18n('maintenance.management.maintenanceWorkTask');
  const { showMessage } = useMessage();
  const { meta } = unref(router.currentRoute);

  const getTitle = {
    icon: meta.icon || 'i-ant-design:book-outlined',
    value: meta.title || t('维保工单流程记录表管理'),
  };
  const maintenanceWorkTaskParams = ref({
    name: ''
  })
  const EnterpriseParams = ref<Recordable>({
    name: ''
  });

  const tableColumns: BasicColumn[] = [
    {
      title: t('工单名称'),
      dataIndex: 'name',
      key: 'a.name',
      sorter: true,
      width: 130,
      align: 'left',
    },
    {
      title: t('单位名称'),
      dataIndex: 'enterpriseName',
      key: 'a.enterprise_name',
      sorter: true,
      width: 130,
      align: 'left',
    },
    {
      title: t('上报时间'),
      dataIndex: 'reportTime',
      key: 'a.report_time',
      sorter: true,
      width: 130,
      align: 'center',
    },
    {
      title: t('工单状态'),
      dataIndex: 'status',
      key: 'a.status',
      sorter: true,
      width: 130,
      align: 'center',
      dictType: 'sys_search_status',
    },
  ];

  const [registerDrawer, { openDrawer }] = useDrawer(); // 初始化抽屉

  const actionColumn: BasicColumn = {
    width: 160,
    actions: (record: Recordable) => [
      {
        label: t('详情'),
        auth: 'maintenance:management:maintenanceWorkTask:edit',
        onClick: () => {
          if (record.tid) {
            // ViewsMaintenanceManagementMaintenanceWorkTaskList 是维护工单列表页的路由名称
            router.push({
              name: 'ViewsMaintenanceManagementMaintenanceWorkTaskList', 
              query: { tid: record.tid }
            }).catch((error) => {
              console.error('路由跳转出错:', error);
            });
          } else {
            console.error('record.tid 未定义，无法跳转');
          }
        }
      },
    ],
  };

  const [registerTable, { reload }] = useTable({
    api: maintenanceWorkTaskListData,
    beforeFetch: (params) => {
      // params.tid = tid.value;
      return params;
    },
    columns: tableColumns,
    actionColumn: actionColumn,
    showTableSetting: true,
    canResize: true,
  });

  function handleSuccess(record: Recordable) {
    reload({ record });
  }
</script>
<style scoped lang="less">
::v-deep #workTaskTableContainer {
  background-color:rgb(9,26,51);
}
::v-deep #workTaskTableContainer .ant-table-body {
  background-color:rgb(9,26,51) !important;
  color: aliceblue;
  border: 1px solid rgb(192, 192, 249);
}
::v-deep #workTaskTableContainer .ant-table-thead > tr > th {
  background-color:rgb(9,26,51); /* 可根据需求修改颜色 */
  color: aliceblue;
  border: 1px solid rgb(192, 192, 249);
}

::v-deep #workTaskTableContainer .ant-table-tbody > tr > td {
  background-color:rgb(9,26,51); /* 可根据需求修改颜色 */
  color: aliceblue;
  border: 1px solid rgb(192, 192, 249);
}

::v-deep #workTaskTableContainer .ant-table-tbody > tr:hover > td {
  background-color:rgb(9,26,51); /* 可根据需求修改颜色 */
  color: aliceblue;
  border: 1px solid rgb(192, 192, 249);
}
::v-deep #workTaskTableContainer .ant-spin-container {
  background-color:rgb(9,26,51);
  color: aliceblue;
  border: 1px solid rgb(192, 192, 249);
}
</style>